package com.wencai.daily;

import org.jetbrains.annotations.NotNull;
import com.wencai.util.IOUtils;

import java.io.File;
import java.io.IOException;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;

/**
 * @author wangpan
 * @date 2023/8/24
 */
public class ShowWencai {
    private static String dir = "D:\\Users\\Administrator\\Desktop\\记录\\概念\\";
    private static String outPath = "D:\\Users\\Administrator\\Desktop\\记录\\近两月异动合并.txt";

    private static Pattern p = Pattern.compile("([^0-9_ \t]+)(_sh\\.\\d+|_sz\\.\\d+)");

    public static void main(String[] args) throws IOException {
        String currentMonth = getString(LocalDate.now());
        String lastMonth = getString(LocalDate.now().plusMonths(-1));
        File f = new File(dir);
        String[] list = f.list();
        Set<String> set = new HashSet<>();
        StringBuilder builder = new StringBuilder();
        for (String str : list) {
            // str.startsWith(currentMonth) || str.startsWith(lastMonth)
            if (str.startsWith("2023")) {
                List<String> lines = IOUtils.readFromFile(dir + str);
                builder.append(str.replace(".txt", "")).append(System.lineSeparator());
                for (String line : lines) {
                    builder.append(line).append(System.lineSeparator());
                }
            }
        }
        System.out.println(builder);
    }

    @NotNull
    private static String getString(LocalDate localDate) {
        Instant instant = localDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();
        return new SimpleDateFormat("YYYYMM").format(Date.from(instant));
    }
}
